Skip to content

uniquify root goals during HIR typeck #144405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 31, 2025
Merged

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jul 24, 2025

We need to rely on region identity to deal with hangs such as rust-lang/trait-system-refactor-initiative#210 and to keep the current behavior of fn try_merge_responses.

This is a problem as borrowck starts by replacing each occurrence of a region with a unique inference variable. This frequently splits a single region during HIR typeck into multiple distinct regions. As we assume goals to always succeed during borrowck, relying on two occurances of a region being identical during HIR typeck causes ICE. See the now fixed examples in rust-lang/trait-system-refactor-initiative#27 and #139409.

We've previously tried to avoid this issue by always uniquifying regions when canonicalizing goals. This prevents caching subtrees during canonicalization which resulted in hangs for very large types. People rely on such types in practice, which caused us to revert our attempt to reinstate #[type_length_limit] in #127670. The complete list of changes here:

After more consideration, all occurrences of such large types need to happen outside of typeck/borrowck. We know this as we already walk over all types in the MIR body when replacing their regions with nll vars.

This PR therefore enables us to rely on region identity inside of the trait solver by exclusively uniquifying root goals during HIR typeck. These are the only goals we assume to hold during borrowck. This is insufficient as type inference variables may "hide" regions we later uniquify. Because of this, we now stash proven goals which depend on inference variables in HIR typeck and reprove them after writeback. This closes rust-lang/trait-system-refactor-initiative#127.

This was originally part of #144258 but I've moved it into a separate PR. While I believe we need to rely on region identity to fix the performance issues in some way, I don't know whether #144258 is the best approach to actually do so. Regardless of how we deal with the hangs however, this change is necessary and desirable regardless.

r? @compiler-errors or @BoxyUwU

@rustbot
Copy link
Collaborator

rustbot commented Jul 24, 2025

compiler-errors is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 24, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 24, 2025

r? BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned compiler-errors Jul 24, 2025
@BoxyUwU BoxyUwU added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2025
@rust-cloud-vms rust-cloud-vms bot force-pushed the hir-typeck-uniquify branch from 53a905a to 0cb0427 Compare July 25, 2025 12:40
@rustbot
Copy link
Collaborator

rustbot commented Jul 25, 2025

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-cloud-vms rust-cloud-vms bot force-pushed the hir-typeck-uniquify branch 2 times, most recently from 5df011f to 5082eab Compare July 25, 2025 12:44
@lcnr
Copy link
Contributor Author

lcnr commented Jul 25, 2025

expect this to result in a minor perf hit

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jul 25, 2025
uniquify root goals during HIR typeck
@rust-bors
Copy link

rust-bors bot commented Jul 25, 2025

⌛ Trying commit 5082eab with merge b91de35

To cancel the try build, run the command @bors try cancel.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 25, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jul 25, 2025

☀️ Try build successful (CI)
Build commit: b91de35 (b91de35e69e61422874a93fd8135dd731eb4baa3, parent: b56aaec52bc0fa35591a872fb4aac81f606e265c)

@rust-timer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the hir-typeck-uniquify branch from 5082eab to c55b6af Compare July 25, 2025 15:28
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b91de35): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.9% [0.1%, 7.6%] 22
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 2.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [1.3%, 3.7%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary 2.2%, secondary 3.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
3.8% [2.1%, 5.3%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [2.2%, 2.2%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 469.891s -> 470.268s (0.08%)
Artifact size: 374.63 MiB -> 374.53 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 25, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Jul 28, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jul 29, 2025
uniquify root goals during HIR typeck
@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

⌛ Trying commit 8927b59 with merge dd57477

To cancel the try build, run the command @bors try cancel.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 29, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

☀️ Try build successful (CI)
Build commit: dd57477 (dd57477a03a5dd1df7485758d47fe05102b79568, parent: 552904134b564a74489db50aebe7070fdcce895c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (dd57477): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [0.2%, 4.1%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [0.8%, 1.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.5% [-4.7%, -4.4%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [2.1%, 4.0%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.6%, -2.1%] 2
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 468.885s -> 467.808s (-0.23%)
Artifact size: 376.79 MiB -> 376.73 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 29, 2025
Comment on lines +1026 to +1028
let mut inner = self.inner.borrow_mut();
inner.undo_log.push(UndoLog::PushHirTypeckPotentiallyRegionDependentGoal);
inner.hir_typeck_potentially_region_dependent_goals.push(goal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questions:
We only let people evaluate goals inside of a probe if the fulfillmentctxt/whatever was also created in that probe?
This codepath just exists to not (incorrectly) leak details from that previous scenario, to outside of the probe?
We don't actually have support for "rolling back" trait solving?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do when using a separate fulfillment context inside of a probe

@lcnr lcnr force-pushed the hir-typeck-uniquify branch from 90c4af1 to df2e543 Compare July 30, 2025 12:01
@lcnr
Copy link
Contributor Author

lcnr commented Jul 30, 2025

@bors r=BoxyUwU rollup=never

@bors
Copy link
Collaborator

bors commented Jul 30, 2025

📌 Commit 2b065e7 has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 30, 2025
@bors
Copy link
Collaborator

bors commented Jul 31, 2025

⌛ Testing commit 2b065e7 with merge 32e7a4b...

@bors
Copy link
Collaborator

bors commented Jul 31, 2025

☀️ Test successful - checks-actions
Approved by: BoxyUwU
Pushing 32e7a4b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 31, 2025
@bors bors merged commit 32e7a4b into rust-lang:master Jul 31, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 31, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 606dcc0 (parent) -> 32e7a4b (this PR)

Test differences

Show 21 test diffs

Stage 1

  • [crashes] tests/crashes/139409.rs: pass -> [missing] (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-1.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-1.rs#next: [missing] -> pass (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-2.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-2.rs#next: [missing] -> pass (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-3.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-3.rs#next: [missing] -> pass (J1)

Stage 2

  • [crashes] tests/crashes/139409.rs: pass -> [missing] (J0)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-1.rs#current: [missing] -> pass (J2)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-1.rs#next: [missing] -> pass (J2)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-2.rs#current: [missing] -> pass (J2)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-2.rs#next: [missing] -> pass (J2)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-3.rs#current: [missing] -> pass (J2)
  • [ui] tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-3.rs#next: [missing] -> pass (J2)

Additionally, 7 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 32e7a4b92b109c24e9822c862a7c74436b50e564 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-x86_64-apple: 7589.3s -> 12320.3s (62.3%)
  2. x86_64-apple-2: 5311.5s -> 4392.8s (-17.3%)
  3. dist-apple-various: 3892.0s -> 4489.3s (15.3%)
  4. dist-x86_64-windows-gnullvm: 5503.8s -> 6076.0s (10.4%)
  5. x86_64-mingw-1: 9380.9s -> 10296.4s (9.8%)
  6. dist-i686-msvc: 7273.5s -> 7891.5s (8.5%)
  7. aarch64-gnu-llvm-19-2: 2301.9s -> 2495.8s (8.4%)
  8. dist-armhf-linux: 4743.7s -> 5109.2s (7.7%)
  9. x86_64-gnu-llvm-20-1: 3274.5s -> 3519.3s (7.5%)
  10. i686-gnu-2: 5702.4s -> 6094.1s (6.9%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (32e7a4b): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [0.1%, 4.1%] 14
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [1.0%, 1.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 468.729s -> 467.812s (-0.20%)
Artifact size: 376.81 MiB -> 376.72 MiB (-0.02%)

@lcnr
Copy link
Contributor Author

lcnr commented Jul 31, 2025

The regression to the new solver is something we kinda how to live with unfortunately. We're gonna change the approach here in the future which may change things, but for now I think moving forward towards being functional is more important

@lcnr lcnr deleted the hir-typeck-uniquify branch July 31, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dealing with region uniquification
7 participants